﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using System.Data;
using System.Xml;
using System.Threading;
//using ApproveLib.WFWebserviceClient;
using System.Web.Configuration;

namespace UCWebpart
{
    public partial class login1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //Worker w = new Worker();
                //w.SendMeetingRequest(st, et, mtrAdd, meetingTheme, body, attendees, ccs,
                //               keyId, false, userName, userName + "@kaifa.cn", false, "");
                //获取url中的AD值
                if (Request.Params["userName"] != null)
                {
                    string getUrl = Request.Params["userName"].ToString();
                    if (getUrl.Contains('\\'))
                    {
                        Session["userName"] = getUrl.Split('\\')[1].ToLower().ToString();
                    }
                    else
                    {
                        Session["userName"] = getUrl;
                    }
                }
                if (Session["userName"] != null)
                {
                    //判断是否在黑名单
                    if (!isInBlackList(Session["userName"].ToString()))
                    {
                        Response.Write("<script>alert('您在黑名单中，暂时不能使用此系统，请联系管理员！'); </script>");
                        return;
                    }
                    string userName = Session["userName"].ToString();
                    Response.Redirect("WEB/BookingManage.aspx", false);
                }
            }
            catch (Exception ex) {
                Worker w = new Worker();
                w.writeErrorMessage("0", ex,"load");
            }
        }

        //判断是否在黑名单
        protected bool isInBlackList(string userName)
        {
            string conn = WebConfigurationManager.ConnectionStrings["meetingroomManagementConnectionString"].ConnectionString;
            string strSql = string.Format("SELECT * from [VenueBooking].[dbo].[blackList] where [available] = 1 and blackName = '{0}'", userName);
            DataTable dt = Worker.GetDataSet(strSql, conn).Tables[0];
            if (dt.Rows.Count >= 1)
            {
                return false;
            }
            else
                return true;
        }
    }
}